/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ManageBean;

import HouseBN.HouseService;
import LinkImageBN.LinkimageService;
import SaveMessage.SavemessageService;
import UserBN.Authentication;
import UserBN.UserService;
import entity.House;
import entity.LinkImage;
import entity.SwhUser;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author Mr-Quick
 */
@ManagedBean
@RequestScoped
public class Detailsmessage {

    public Detailsmessage() {
    }
    String idhouse;
    List<LinkImage> listimage;
    public String getIdhouse() {
        return idhouse;
    }

    public void setIdhouse(String idhouse) {
        this.idhouse = idhouse;
        Getdetailmessage();
        Getlinkimagefordetailmassage();
    }

    public List<LinkImage> getListimage() {
        return listimage;
    }

    public void setListimage(List<LinkImage> listimage) {
        this.listimage = listimage;
    }
        
    House house;

    public House getHouse() {
        return house;
    }

    public void setHouse(House house) {
        this.house = house;
    }

    public void Getdetailmessage() {
        HouseService hs = new HouseService();
        setHouse(hs.Gethousebyid(idhouse)); 
    }
    public void Getlinkimagefordetailmassage()
    {
        LinkimageService lis = new LinkimageService();
        listimage = lis.Getlinkimagebyidhouse(idhouse);
    }
    public void Savetomymessage()
    {
        Authentication a = Authentication.getInstance();
        String account = a.getUsername();
        UserService us = new UserService();
        SwhUser u = us.findAccountByUsername(account);
        HouseService hs = new HouseService();
        House h = hs.Gethousebyid(idhouse);
        SavemessageService ss = new SavemessageService();
        if("true".equals(ss.Createsavemessage(u,h)))
        {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Add in Your Message Success",  "Add in Your Message Success");  
            FacesContext.getCurrentInstance().addMessage(null, message);  
        }
        else
        {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "This Message had in your message",  "This Message had in your message");  
            FacesContext.getCurrentInstance().addMessage(null, message); 
        }          
    }
    public String viewIduserUp()
    {
        return "IDProfile.xhtml?faces-redirect=true&idP="+house.getIDUser();
    }
    
}
